package cc.javaee.bbs.controller.awardInfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cc.javaee.bbs.model.AwardInfo;
import cc.javaee.bbs.model.Bankuai;
import cc.javaee.bbs.model.JifenGroup;
import cc.javaee.bbs.model.PageBean;
import cc.javaee.bbs.model.User;
import cc.javaee.bbs.model.Zhuti;
import cc.javaee.bbs.service.awardInfo.AwardInfoService;
/**
 * 奖品controller
 * @author admin
 *
 */
@Controller
@RequestMapping("/admin/awardInfo")
public class AwardInfoController {

	@Autowired
	private AwardInfoService awardInfoService;
	
	//跳转首页
	@RequestMapping("index.do")
	public String add(HttpServletRequest request, Model model,AwardInfo awardInfo,PageBean<AwardInfo> page) {
		page = awardInfoService.findpage(awardInfo,page);
		model.addAttribute("page", page);
		model.addAttribute("qAwardInfo", awardInfo);
		return "jsp/admin/awardInfo/index";
	}
	@RequestMapping("tooptions.do")
	public String tooptions(HttpServletRequest request, Model model,AwardInfo awardInfo){
		awardInfo = awardInfoService.findbyid(awardInfo);
		model.addAttribute("awardInfo", awardInfo);
		return "jsp/admin/awardInfo/option";
	}
   //跳转到修改页面
	@RequestMapping("toupdateoradd.do")
	public String toupdateoradd(AwardInfo awardInfo, Model model) {
		if(awardInfo.getId()!=null){
			awardInfo=awardInfoService.findbyid(awardInfo);
		}
		model.addAttribute("awardInfo", awardInfo);
		return "jsp/admin/awardInfo/updateoradd";
	}
	//修改或者新增
	@RequestMapping("updateoradd.do")
	public String updateoradd(AwardInfo awardInfo) {
		if(awardInfo.getId()!=null){
			awardInfoService.update(awardInfo);
		}else{
			awardInfoService.insert(awardInfo);
		}
		return "redirect:index.do";
	}
	/**
	 * 根据活动id查询奖品 App接口
	 * @param activeId 活动id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/findOrderInfoByActiveId.do")
	public Map<String,Object>findOrderInfoByActiveId(@RequestParam("activeId")String activeId){
		Map<String,Object>map=new HashMap<>();
		if(activeId==null || activeId==""){
			map.put("status","0");
			return map;
		}
	   List<AwardInfo>list=awardInfoService.findOrderInfoByActiveId(activeId);
	   map.put("status", "1");
	   map.put("awardInfos", list);
	   return map;
	}
	     //删除
		@ResponseBody
		@RequestMapping("del.do")
		public String del(int id) {
			String result=awardInfoService.delete(id);
			return result;
		}
}
